﻿package core.ui.controls
{
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.geom.*;
    import flash.text.*;

    public class Box extends Sprite
    {
        public var ed:Tuyitu;
        public var close:IconButton;
        private var drag:Sprite;
        private var t:TextField;
        private var tl:Bitmap;
        private var tm:Bitmap;
        private var tr:Bitmap;
        private var ml:Bitmap;
        private var mm:Bitmap;
        private var mr:Bitmap;
        private var bl:Bitmap;
        private var bm:Bitmap;
        private var br:Bitmap;

        public function Box(param1:Tuyitu, param2:String, param3:int, param4:int)
        {
            this.ed = param1;
            this.filters = [new DropShadowFilter(0, 45, 0, 0.4, 10, 10, 1, 3, false)];
            var _loc_5:* = new BoxBg();
            var _loc_6:* = new BitmapData(24, 50, true, 16777215);
            _loc_6.copyPixels(_loc_5, new Rectangle(0, 0, 24, 18), new Point(0, 0));
            _loc_6.copyPixels(_loc_5, new Rectangle(0, 27, 24, 32), new Point(0, 18));
            this.tl = new Bitmap(_loc_6);
            addChild(this.tl);
            var _loc_7:* = new BitmapData(2, 50, true, 16777215);
            _loc_7.copyPixels(_loc_5, new Rectangle(24, 0, 2, 18), new Point(0, 0));
            _loc_7.copyPixels(_loc_5, new Rectangle(24, 27, 2, 32), new Point(0, 18));
            this.tm = new Bitmap(_loc_7);
            addChild(this.tm);
            var _loc_8:* = new BitmapData(24, 50, true, 16777215);
            _loc_8.copyPixels(_loc_5, new Rectangle(26, 0, 24, 18), new Point(0, 0));
            _loc_8.copyPixels(_loc_5, new Rectangle(26, 27, 24, 32), new Point(0, 18));
            this.tr = new Bitmap(_loc_8);
            addChild(this.tr);
            this.ml = new Bitmap(UI.GetPart(_loc_5, 0, 55, 24, 2));
            addChild(this.ml);
            this.mm = new Bitmap(UI.GetPart(_loc_5, 24, 55, 2, 2));
            addChild(this.mm);
            this.mr = new Bitmap(UI.GetPart(_loc_5, 26, 55, 24, 2));
            addChild(this.mr);
            this.bl = new Bitmap(UI.GetPart(_loc_5, 0, 57, 24, 10));
            addChild(this.bl);
            this.bm = new Bitmap(UI.GetPart(_loc_5, 24, 57, 2, 10));
            addChild(this.bm);
            this.br = new Bitmap(UI.GetPart(_loc_5, 26, 57, 24, 10));
            addChild(this.br);
            _loc_5.dispose();
            _loc_5 = null;
            this.t = new TextField();
            this.t.defaultTextFormat = new TextFormat("Arial,Helvetica,San-serif", AppState.TextSize, 16777215, false, false, false, null, null, "center");
            var _loc_9:Boolean = false;
            this.t.selectable = false;
            this.t.multiline = _loc_9;
            this.t.text = U.RM(param2);
            this.t.height = 18;
            addChild(this.t);
            this.drag = new Sprite();
            this.drag.addEventListener(MouseEvent.MOUSE_DOWN, this.DragMouseDown, false, 0, true);
            this.drag.graphics.beginFill(9474192);
            this.drag.graphics.drawRect(0, 0, 100, 100);
            this.drag.graphics.endFill();
            var _loc_9:int = 1;
            this.drag.y = 1;
            this.drag.x = _loc_9;
            this.drag.height = 17;
            this.drag.alpha = 0;
            addChild(this.drag);
            this.close = new IconButton(param1, "rm_close", new CloseOn());
            this.close.addEventListener(MouseEvent.MOUSE_UP, this.CloseClick, false, 0, true);
            addChild(this.close);
            this.Resize(param3, param4);
            return;
        }// end function

        public function Resize(core.ui.controls:int, core.ui.controls:int) : void
        {
            if (core.ui.controls < 50)
            {
                core.ui.controls = 50;
            }
            if (core.ui.controls < 60)
            {
                core.ui.controls = 60;
            }
            var _loc_3:* = core.ui.controls - 48;
            this.bm.width = core.ui.controls - 48;
            var _loc_3:* = _loc_3;
            this.mm.width = _loc_3;
            this.tm.width = _loc_3;
            var _loc_3:* = core.ui.controls - 60;
            this.mr.height = core.ui.controls - 60;
            var _loc_3:* = _loc_3;
            this.mm.height = _loc_3;
            this.ml.height = _loc_3;
            var _loc_3:int = 24;
            this.bm.x = 24;
            var _loc_3:* = _loc_3;
            this.mm.x = _loc_3;
            this.tm.x = _loc_3;
            var _loc_3:* = this.tm.width + 24;
            this.br.x = this.tm.width + 24;
            var _loc_3:* = _loc_3;
            this.mr.x = _loc_3;
            this.tr.x = _loc_3;
            var _loc_3:int = 50;
            this.mr.y = 50;
            var _loc_3:* = _loc_3;
            this.mm.y = _loc_3;
            this.ml.y = _loc_3;
            var _loc_3:* = this.mm.height + 50;
            this.bl.y = this.mm.height + 50;
            var _loc_3:* = _loc_3;
            this.bm.y = _loc_3;
            this.br.y = _loc_3;
            this.t.width = core.ui.controls;
            this.drag.width = core.ui.controls - 2;
            this.close.y = 4;
            this.close.x = core.ui.controls - 17;
            return;
        }// end function

        public function CloseClick(event:MouseEvent) : void
        {
            this.visible = false;
            return;
        }// end function

        function DragMouseDown(event:MouseEvent) : void
        {
            this.startDrag(false, new Rectangle((-this.width) / 2, 40, stage.stageWidth, stage.stageHeight + 1000));
            stage.addEventListener(MouseEvent.MOUSE_UP, this.DragMouseUp, true, 0, true);
            return;
        }// end function

        function DragMouseUp(event:MouseEvent) : void
        {
            this.stopDrag();
            stage.removeEventListener(MouseEvent.MOUSE_UP, this.DragMouseUp, true);
            return;
        }// end function

        public function set title(core.ui.controls:String) : void
        {
            this.t.text = core.ui.controls;
            return;
        }// end function

    }
}
